#include <basic_types.h>
#include <api/libosd/osd_lib.h>
static	VSCR m_vscr_dest;

static 	PVSCR_LIST   plist_cur;
//static	INT effect_draw_cnt;


extern PVSCR_LIST  pVscrHead;
extern   BufferAdd;
//extern aladdin_tmp_y;

#define MAX_PIXEL_W 400
#define MAX_PIXEL_H  100
//typedef INT32 *light_sphere_para[MAX_PIXEL_H];
//aladdin_light_value
//light_sphere_para  aladdin_light_value;

int lightvalue_flag=0;
int Slide_direction=1;
INT32 *light_value;
typedef struct tagITEM
{

    VSCR src;
    VSCR oldsrc;
    DRAW_STYLE style;
    struct tagITEM *next;
}DRAW_SRC_ITEM,*PDRAW_SRC_ITEM;


BOOL OSD_Get_Area(VSCR* psrc_vscr, VSCR *pdest_vscr)
{
    BOOL ret;
	int loop;
	UINT8 *buffer1,*buffer2;
    if(OSD_RectInRect((struct OSDRect*)psrc_vscr,(struct OSDRect*)pdest_vscr))
    {
        for(loop = 0; loop < pdest_vscr->vR.uHeight; loop++)
        {
        	buffer2 = pdest_vscr->lpbScr + OSD_GetPitchColorMode(pdest_vscr->bColorMode,pdest_vscr->vR.uWidth) * loop ;
            buffer1 = psrc_vscr->lpbScr + OSD_GetPitchColorMode(psrc_vscr->bColorMode,psrc_vscr->vR.uWidth)*(loop + (pdest_vscr->vR.uTop - psrc_vscr->vR.uTop)) 
        			+ OSD_GetPixelSize(psrc_vscr->bColorMode)*(pdest_vscr->vR.uLeft - psrc_vscr->vR.uLeft);
        	MEMCPY(buffer2,buffer1 ,OSD_GetPitchColorMode(pdest_vscr->bColorMode,pdest_vscr->vR.uWidth));

        }
        ret = TRUE;        
    }
    else
    {
        ret = FALSE;
    }
    return ret;
}

BOOL OSD_Set_Area(VSCR* psrc_vscr, VSCR *pdest_vscr)
{
    BOOL ret;
	int loop;
	UINT8 *buffer1,*buffer2;
    if(OSD_RectInRect((struct OSDRect*)psrc_vscr,(struct OSDRect*)pdest_vscr))
    {
        for(loop = 0; loop < pdest_vscr->vR.uHeight; loop++)
        {
        	buffer2 = pdest_vscr->lpbScr + OSD_GetPitchColorMode(pdest_vscr->bColorMode,pdest_vscr->vR.uWidth) * loop ;
        	buffer1 = psrc_vscr->lpbScr + OSD_GetPitchColorMode(psrc_vscr->bColorMode,psrc_vscr->vR.uWidth)*(loop+(pdest_vscr->vR.uTop -psrc_vscr->vR.uTop)) 
        			+ OSD_GetPixelSize(psrc_vscr->bColorMode)*(pdest_vscr->vR.uLeft - psrc_vscr->vR.uLeft);
        	MEMCPY(buffer1,buffer2,OSD_GetPitchColorMode(pdest_vscr->bColorMode,pdest_vscr->vR.uWidth));
        }
        ret = TRUE;
    }
    else
    {
        ret = FALSE;
    }
    return ret;
}

UINT32 OSD_Get_OSDBuffer_Area(VSCR *pVscr)
{
    UINT32 ret = 0;
    ret = OSDLib_RegionRead(pVscr,&pVscr->vR);
    return ret;
}
#if 0
void OSD_DrawMode_LightSphere(VSCR* pVscr,PVSCR_LIST   plist,VSCR m_vscr)
{
    int loop,iy;
    int len=90;
    int ang_per_time=180/len;
    // VSCR m_vscr_dest;
    VSCR m_vscr_2;
    m_vscr_2=m_vscr;
    Aladdin_fill_frame_new_16bit(0,0, m_vscr.vR.uWidth, m_vscr.vR.uWidth,m_vscr.vR.uHeight,&( m_vscr.lpbScr), BufferAdd);
    m_vscr_dest.vR = m_vscr.vR;
    for(loop=0;loop<len;loop++)
    {
        // if (aladdin_tmp_y>30)
        Aladdin_texture_light_sphere_starage_value_16bitdemo(m_vscr_2.lpbScr,m_vscr_2.vR.uWidth,m_vscr_2.vR.uHeight, m_vscr_2.vR.uWidth>>1,m_vscr_2.vR.uHeight>>1,0,  (plist->vscr.vR.uHeight>>1)-2,m_vscr_2.vR.uWidth, 270+loop*ang_per_time, aladdin_light_value,BufferAdd);
        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
    }

}

void OSD_DrawMode_Transform(VSCR* pVscr,PVSCR_LIST   plist,VSCR m_vscr,VSCR m_vscr_2)
{
    int loop;
    int len=200;
    //VSCR m_vscr_dest;
    m_vscr_dest = m_vscr;
    for(loop=0;loop<len;loop++)
    {
        Aladdin_new_transform_16bitdemo(m_vscr_2.lpbScr, m_vscr.lpbScr, 0,0,m_vscr_2.vR.uWidth,m_vscr_2.vR.uWidth,m_vscr_2.vR.uHeight, loop+1, len, BufferAdd);
        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
    }
    OSDLib_RegionWrite(&m_vscr, &(m_vscr.vR));
    free(m_vscr_2.lpbScr);
    //free(m_vscr_dest.lpbScr);

}


void OSD_DrawMode_Rotate(VSCR* pVscr,PVSCR_LIST   plist,VSCR m_vscr)
{
    int loop;
    int len=360;
    int ang_per_time=360/len;
    VSCR m_vscr_dest;
    m_vscr_dest.vR=m_vscr.vR;
    for(loop=0;loop<len;loop++)
    {
        Aladdin_showbmp_rotate_16bitdemo(m_vscr.lpbScr, m_vscr.vR.uWidth,m_vscr.vR.uHeight,0,0,m_vscr.vR.uWidth, loop* ang_per_time, m_vscr_dest.lpbScr);
        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
    }
    OSDLib_RegionWrite(&m_vscr, &(m_vscr.vR));
    //free(m_vscr_dest.lpbScr);					
}


void OSD_DrawMode_Slide(VSCR* pVscr,PVSCR_LIST   plist,VSCR m_vscr)
{
    int loop;
    int len=100;
    int len_per_time=m_vscr.vR.uWidth/len;
    // VSCR m_vscr_dest;
    m_vscr_dest.vR=m_vscr.vR;
    for(loop=0;loop<len;loop++)
    {
        Aladdin_showbmp_texture_scale_2nd_16bitdemo(m_vscr, m_vscr.vR.uWidth, m_vscr.vR.uHeight, 0, 0, len*len_per_time, m_vscr.vR.uHeight, BufferAdd);
        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
    }
    OSDLib_RegionWrite(&m_vscr, &(m_vscr.vR));
}
#else

void OSD_DrawMode_LightSphere(VSCR *m_vscr_new,VSCR *m_vscr_old)
{
	    int loop,iy;
	    VSCR m_vscr_dest;
	    UINT16 color;
	    int len=90;
    	    int ang_per_time=180/len;
	    m_vscr_dest = *m_vscr_old;

	     int R=(m_vscr_new->vR.uHeight>>1)-1;
	     color = ((UINT16 *)(m_vscr_old->lpbScr))[0]; 
	         Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);
	
	    for(loop=0;loop<len;loop++)
	    {
	        Aladdin_texture_light_sphere_new_16bitdemo(m_vscr_old->lpbScr,m_vscr_old->vR.uWidth,m_vscr_old->vR.uHeight \
				                  , m_vscr_old->vR.uWidth>>1,m_vscr_new->vR.uHeight>>1,0,  R,m_vscr_new->vR.uWidth, 90+loop*ang_per_time, light_value,BufferAdd);
	        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
	        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
	    }

	    for(loop=0;loop<len;loop++)
	    {
	        Aladdin_texture_light_sphere_new_16bitdemo(m_vscr_new->lpbScr,m_vscr_new->vR.uWidth,m_vscr_new->vR.uHeight \
				                   , m_vscr_new->vR.uWidth>>1,m_vscr_new->vR.uHeight>>1,0,  R,m_vscr_new->vR.uWidth, 270+loop*ang_per_time, light_value,BufferAdd);
	        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
	        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
	    }
	
}

void OSD_DrawMode_Transform(VSCR *m_vscr_new,VSCR *m_vscr_old)
{
	    int loop;
	    int len=200;
	    VSCR m_vscr_dest;
	    m_vscr_dest = *m_vscr_new;
	    OSDLib_RegionWrite(m_vscr_new, &(m_vscr_new->vR));

	    for(loop=0;loop<len;loop++)
	    {
	        Aladdin_new_transform_16bitdemo(m_vscr_old->lpbScr, m_vscr_new->lpbScr, 0,0 \
				,m_vscr_old->vR.uWidth,m_vscr_old->vR.uWidth,m_vscr_old->vR.uHeight, loop+1, len, BufferAdd);
	        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
	        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
	    }
	    //OSDLib_RegionWrite(m_vscr_new, &(m_vscr_new->vR));

}


void OSD_DrawMode_Rotate(VSCR *m_vscr,VSCR *m_vscr_old)
{
	    int loop;
	    UINT16 color;
	    VSCR m_vscr_dest;
	    m_vscr_dest = *m_vscr_old;
	    int len;
		if (((UINT32)m_vscr_dest.vR.uWidth*(UINT32)m_vscr_dest.vR.uHeight>=80000)&&((UINT32)m_vscr_dest.vR.uWidth*(UINT32)m_vscr_dest.vR.uHeight<100000))
			{len=45;color = ((UINT16 *)(m_vscr_old->lpbScr))[0]; }
		else if (((UINT32)m_vscr_dest.vR.uWidth*(UINT32)m_vscr_dest.vR.uHeight>=100000)&&((UINT32)m_vscr_dest.vR.uWidth*(UINT32)m_vscr_dest.vR.uHeight<300000))
			{len=30;			    
			color = ((UINT16 *)(m_vscr_old->lpbScr))[0]; 
			}
		else if ((UINT32)m_vscr_dest.vR.uWidth*(UINT32)m_vscr_dest.vR.uHeight>=300000)
			{
			      len=15;
			      color = 00;
		        }
		else 
			{
			    len=90;
			    color = ((UINT16 *)(m_vscr_old->lpbScr))[0]; 
			}
	    int ang_per_time=90/len;
	    for(loop=0;loop<len;loop++)
	    {
	       Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);
	        Aladdin_showbmp_rotate_16bitdemo(m_vscr_old->lpbScr, m_vscr_old->vR.uWidth,m_vscr_old->vR.uHeight
	                                ,0,0,m_vscr_old->vR.uWidth, loop* ang_per_time, BufferAdd);
	        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
	        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
	    }
	    m_vscr_dest = *m_vscr;
	    for(loop=0;loop<len;loop++)
	    {
	       Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);
	        Aladdin_showbmp_rotate_16bitdemo(m_vscr->lpbScr, m_vscr->vR.uWidth,m_vscr->vR.uHeight
	                                ,0,0,m_vscr->vR.uWidth, loop* ang_per_time+270, BufferAdd);
	        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
	        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
	    }
}


void OSD_DrawMode_Slide(VSCR *m_vscr,VSCR *m_vscr_old)
{
    int loop,len;
    len=100;
    int len_per_time=m_vscr->vR.uWidth/len;
    VSCR m_vscr_dest;
	UINT16 color;
	int Xbegin;
    m_vscr_dest = *m_vscr;
    color = ((UINT16 *)(m_vscr->lpbScr))[0]; 
    Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);

    for(loop=0;loop<len;loop++)
    {
  	if(Slide_direction==1)
		Xbegin=0;
	else
		Xbegin=m_vscr->vR.uWidth-(loop+1)*len_per_time-1;
	Aladdin_showbmp_texture_scale_2nd_16bitdemo(m_vscr->lpbScr, m_vscr->vR.uWidth, m_vscr->vR.uHeight
		                                  , Xbegin, 0,(loop+1)*len_per_time, m_vscr->vR.uHeight, m_vscr->vR.uWidth,BufferAdd);
        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
    }
		    for(loop=1;loop<=20;loop++)
		    {
		  	if(Slide_direction==1)
				Xbegin=0;
			else
				Xbegin=loop-1;
		   	 Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);
		        Aladdin_showbmp_texture_scale_2nd_16bitdemo(m_vscr->lpbScr, m_vscr->vR.uWidth, m_vscr->vR.uHeight
					                        , Xbegin, 0,m_vscr->vR.uWidth-loop, m_vscr->vR.uHeight, m_vscr->vR.uWidth,BufferAdd);
		        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
		        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
		    }
		    for(loop=1;loop<=20;loop++)
		    {
		  	if(Slide_direction==1)
				Xbegin=0;
			else
				Xbegin=20-loop-1;
			 Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);
		        Aladdin_showbmp_texture_scale_2nd_16bitdemo(m_vscr->lpbScr, m_vscr->vR.uWidth, m_vscr->vR.uHeight
					                 , Xbegin, 0,m_vscr->vR.uWidth-20+loop, m_vscr->vR.uHeight, m_vscr->vR.uWidth,BufferAdd);
		        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
		        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
		    }
		    for(loop=1;loop<=10;loop++)
		    {
		  	if(Slide_direction==1)
				Xbegin=0;
			else
				Xbegin=loop-1;
		  	 Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);
		        Aladdin_showbmp_texture_scale_2nd_16bitdemo(m_vscr->lpbScr, m_vscr->vR.uWidth, m_vscr->vR.uHeight
					                      , Xbegin, 0,m_vscr->vR.uWidth-loop, m_vscr->vR.uHeight, m_vscr->vR.uWidth,BufferAdd);
		        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
		        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
		    }
		    for(loop=1;loop<=10;loop++)
		    {
		  	if(Slide_direction==1)
				Xbegin=0;
			else
				Xbegin=10-loop-1;
			 Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);
		        Aladdin_showbmp_texture_scale_2nd_16bitdemo(m_vscr->lpbScr, m_vscr->vR.uWidth, m_vscr->vR.uHeight
					                 , Xbegin, 0,m_vscr->vR.uWidth-10+loop, m_vscr->vR.uHeight, m_vscr->vR.uWidth,BufferAdd);
		        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
		        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
		    }
		    for(loop=1;loop<=5;loop++)
		    {
		  	if(Slide_direction==1)
				Xbegin=0;
			else
				Xbegin=loop-1;
		    	 Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);
		        Aladdin_showbmp_texture_scale_2nd_16bitdemo(m_vscr->lpbScr, m_vscr->vR.uWidth, m_vscr->vR.uHeight
					                      , Xbegin, 0,m_vscr->vR.uWidth-loop, m_vscr->vR.uHeight, m_vscr->vR.uWidth,BufferAdd);
		        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
		        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
		    }
		    for(loop=1;loop<=5;loop++)
		    {
		  	if(Slide_direction==1)
				Xbegin=0;
			else
				Xbegin=5-loop-1;
		        Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);

		        Aladdin_showbmp_texture_scale_2nd_16bitdemo(m_vscr->lpbScr, m_vscr->vR.uWidth, m_vscr->vR.uHeight
					                  , Xbegin, 0,m_vscr->vR.uWidth-5+loop, m_vscr->vR.uHeight, m_vscr->vR.uWidth,BufferAdd);
		        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
		        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
		    }
   			OSDLib_RegionWrite(m_vscr, &(m_vscr->vR));

	if (Slide_direction==1)
		Slide_direction=0;
	else
		Slide_direction=1;
}

void OSD_DrawMode_Zoom(VSCR *m_vscr,VSCR *m_vscr_old)
{
    int loop;
    int uW,uH,uX,uY;
    UINT16 color,len;
    VSCR m_vscr_dest;
    m_vscr_dest = *m_vscr_old;
	if ((UINT32)m_vscr_dest.vR.uWidth>300)
		{
   		color = 00;
		len=20;
		}
       else
       	{
   		color = ((UINT16 *)(m_vscr_old->lpbScr))[0];
		len=35;
       	}
       int step_x=(m_vscr_dest.vR.uWidth>>1)/len;
       int step_y=(m_vscr_dest.vR.uHeight>>1)/len;
	int Center_x=m_vscr_dest.vR.uWidth>>1;
	int Center_y=m_vscr_dest.vR.uHeight>>1;
       Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);

    for(loop=1;loop<len;loop++)
    {
        uX= Center_x-(len-loop)*step_x;
	 uY= Center_y-(len-loop)*step_y;
        uW=((len-loop)*step_x)<<1;
	 uH=((len-loop)*step_y)<<1;
       Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);
        Aladdin_showbmp_texture_scale_2nd_16bitdemo(m_vscr_old->lpbScr, m_vscr_old->vR.uWidth, m_vscr_old->vR.uHeight  \
			                                                                     , uX,uY,uW, uH, m_vscr_old->vR.uWidth,BufferAdd);
        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
    }

       Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);
	for(loop=1;loop<=len;loop++)
    {
        uX= Center_x-loop*step_x;
	 uY= Center_y-loop*step_y;
        uW=(loop*step_x)<<1;
	 uH=(loop*step_y)<<1;

        Aladdin_showbmp_texture_scale_2nd_16bitdemo(m_vscr->lpbScr, m_vscr->vR.uWidth, m_vscr->vR.uHeight   \
			                                                                         , uX,uY,uW, uH, m_vscr->vR.uWidth,BufferAdd);
        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
    }
    OSDLib_RegionWrite(m_vscr, &(m_vscr->vR));
}


void OSD_DrawMode_Flip(VSCR *m_vscr,VSCR *m_vscr_old)
{
	    int loop,len;
	    UINT16 color;
	    VSCR m_vscr_dest;
	    m_vscr_dest = *m_vscr_old;
	if ((UINT32)m_vscr_dest.vR.uWidth>300)
		{
		    color = 00;//((UINT16 *)(m_vscr_old->lpbScr))[0]; 
		    len=10;
		}
	else
		{
		    color = ((UINT16 *)(m_vscr_old->lpbScr))[0]; 
		    len=45;
		}
	    int ang_per_time=90/len;
	    for(loop=0;loop<len;loop++)
	    {
	    Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);
	       Aladdin_showbmp_singlepage_16bitdemo(m_vscr_old->lpbScr, m_vscr_old->vR.uWidth,m_vscr_old->vR.uHeight
		   	                   , m_vscr_old->vR.uWidth,0,(loop+1)*ang_per_time+180,m_vscr_old->vR.uWidth, BufferAdd);
	        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
	        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
	    }
	    Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);
	        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
	        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));

	    for(loop=0;loop<len;loop++)
	    {
	       Aladdin_showbmp_singlepage_16bitdemo(m_vscr->lpbScr, m_vscr->vR.uWidth,m_vscr->vR.uHeight
		   	                   , 0,0, (loop+1)*ang_per_time+270,m_vscr->vR.uWidth, BufferAdd);
	        m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
	        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
	    }
	    OSDLib_RegionWrite(m_vscr, &(m_vscr->vR));
}


void OSD_DrawMode_Moving(VSCR *m_vscr,VSCR *m_vscr_old)
{
	    int loop;
	    int Xbegin,len;
	    UINT16 color;
	    VSCR m_vscr_dest;
	    m_vscr_dest = *m_vscr_old;
	    color = ((UINT16 *)(m_vscr_old->lpbScr))[0]; 
	if (m_vscr_dest.vR.uWidth>300)
	       len=30;
	else
		len=100;
	    int len_per_time=m_vscr_dest.vR.uWidth/len;
		
	    Aladdin_fill_frame_new_16bit(0,0, m_vscr_dest.vR.uWidth, m_vscr_dest.vR.uWidth,m_vscr_dest.vR.uHeight, color, BufferAdd);
	    for(loop=1;loop<=len;loop++)
	    {
	           Xbegin=loop*len_per_time;
		        Aladdin_showbmp_texture_Rmoving_16bitdemo(m_vscr->lpbScr, m_vscr->vR.uWidth, m_vscr->vR.uHeight
					                  , 0, 0,Xbegin,  m_vscr->vR.uWidth,BufferAdd);
                     if (Xbegin<m_vscr_dest.vR.uWidth)
                     	{
		        Aladdin_showbmp_texture_Lmoving_16bitdemo(m_vscr_old->lpbScr, m_vscr_old->vR.uWidth, m_vscr_old->vR.uHeight
					                  , Xbegin, 0,m_vscr_old->vR.uWidth-Xbegin,  m_vscr_old->vR.uWidth,BufferAdd);
                     	}
			m_vscr_dest.lpbScr = (UINT8 *)BufferAdd;
	        OSDLib_RegionWrite(&m_vscr_dest, &(m_vscr_dest.vR));
	    }
	    OSDLib_RegionWrite(m_vscr, &(m_vscr->vR));
}


#endif
void OSD_DrawMode(VSCR* pVscr,PVSCR_LIST   plist)
{
    PVSCR_LIST p_lst,p_lsthd;
    PDRAW_SRC_ITEM phead,pcur,pnode;
    int i = 0;
    p_lst = plist;
    p_lsthd = NULL;
    phead = pcur = pnode = NULL;
    while(p_lst != NULL)
    {
        switch(p_lst->vscr.bDrawMode)
        {
            case DRAW_STYLE_FADE:
            case DRAW_STYLE_SPHERE:
            case DRAW_STYLE_ROTATE:
            case DRAW_STYLE_SLIDE:  
            case DRAW_STYLE_ZOOM:
            case DRAW_STYLE_FLIP:
            case DRAW_STYLE_MOVE:
                pnode =(PDRAW_SRC_ITEM) MALLOC(sizeof(DRAW_SRC_ITEM));
                MEMSET(pnode,0x00,sizeof(DRAW_SRC_ITEM));
                pnode->src = pnode->oldsrc = p_lst->vscr;
                pnode->oldsrc.lpbScr = MALLOC(OSD_GetPitchColorMode(p_lst->vscr.bColorMode,p_lst->vscr.vR.uWidth) * p_lst->vscr.vR.uHeight);
                MEMSET(pnode->oldsrc.lpbScr,0x00,OSD_GetPitchColorMode(p_lst->vscr.bColorMode,p_lst->vscr.vR.uWidth) * p_lst->vscr.vR.uHeight);    
                pnode->src.lpbScr = MALLOC(OSD_GetPitchColorMode(p_lst->vscr.bColorMode,p_lst->vscr.vR.uWidth) * p_lst->vscr.vR.uHeight);

		        MEMSET(pnode->src.lpbScr,0x00,OSD_GetPitchColorMode(p_lst->vscr.bColorMode,p_lst->vscr.vR.uWidth) * p_lst->vscr.vR.uHeight);    
                OSD_Get_Area(pVscr,&(pnode->src));
                OSD_Get_OSDBuffer_Area(&pnode->oldsrc);  
                OSD_Set_Area(pVscr,&pnode->oldsrc);
	         //libc_printf("malloc_pnode:%x ,%x,%x\n",pnode,pnode->src.lpbScr,pnode->oldsrc.lpbScr);	
                break;
            default:
                SDBBP();
                break;
        }
        if(phead == NULL)
        {
            phead =  pnode;
            pcur  =  pnode;
        }
        else
        {
            pcur->next = pnode;
            pcur = pnode;
        }
        p_lsthd = p_lst;
        p_lst = p_lst->pNext;
        free(p_lsthd);
    }
    OSDLib_RegionWrite(pVscr,&pVscr->vR);
    pcur = phead;
    while(pcur != NULL)
    {
        if(pcur->src.bDrawMode==DRAW_STYLE_SPHERE)
        {
            if(lightvalue_flag!=1)
            {
               light_value=(INT32 *)MALLOC(sizeof(INT32)*(pcur->src.vR.uHeight)*(pcur->src.vR.uHeight));
               storage_value_16bit(100, 100,-100, (pcur->src.vR.uHeight>>1)-1, light_value);
		       lightvalue_flag = 1;
            }
            OSD_DrawMode_LightSphere(&pcur->src,&pcur->oldsrc);
        }
        else if(pcur->src.bDrawMode==DRAW_STYLE_FADE)
        {
            OSD_DrawMode_Transform(&pcur->src,&pcur->oldsrc);
        }
        else if(pcur->src.bDrawMode==DRAW_STYLE_ROTATE)
      	{
            OSD_DrawMode_Rotate(&pcur->src,&pcur->oldsrc);
        }
        else if(pcur->src.bDrawMode==DRAW_STYLE_SLIDE)
        {
             OSD_DrawMode_Slide(&pcur->src,&pcur->oldsrc);
        }
	    else if(pcur->src.bDrawMode==DRAW_STYLE_ZOOM)
	    {
		    OSD_DrawMode_Zoom(&pcur->src,&pcur->oldsrc);
	    }
        else if(pcur->src.bDrawMode==DRAW_STYLE_FLIP)
        {
             OSD_DrawMode_Flip(&pcur->src,&pcur->oldsrc);
        }
        else if(pcur->src.bDrawMode==DRAW_STYLE_MOVE)
        {
             OSD_DrawMode_Moving(&pcur->src,&pcur->oldsrc);
        }
        else
            OSD_DrawMode_Transform(&pcur->src,&pcur->oldsrc);

        OSD_Set_Area(pVscr,&pcur->src);
        pnode = pcur;
        pcur = pcur->next;
        if(pnode->src.lpbScr != NULL)
           free(pnode->src.lpbScr);

        if(pnode->oldsrc.lpbScr != NULL)
        {
           free(pnode->oldsrc.lpbScr);
        }
        free(pnode);	
    }
}

UINT32 OSD_DrawMode_init(OSD_RECT *rect,UINT32 colormode)
{
    extern struct OSDRect g_osd_region_rect;    
    BufferAdd = (UINT32)MALLOC(OSD_GetPixelSize(colormode)*rect->uHeight*rect->uWidth);
    if(BufferAdd == 0)
    {
        SDBBP();
    }
    g_osd_region_rect.uTop = 0;
    g_osd_region_rect.uLeft = 0;
    g_osd_region_rect.uWidth = rect->uWidth;
    g_osd_region_rect.uWidth = rect->uHeight;
    return 0;
}


